package com.ys168.gam.component;

import java.awt.Component;

import javax.swing.DefaultListCellRenderer;
import javax.swing.JList;

import com.ys168.gam.basic.IRenderIcon;
import com.ys168.gam.basic.IRenderText;

/**
 * @author Jason Krebs
 * @since 2015年6月12日
 */
public class JKListCellRender extends DefaultListCellRenderer {

    private static final long serialVersionUID = 6330983341711321007L;

    @Override
    public Component getListCellRendererComponent(JList<? extends Object> list, Object value, int index,
            boolean isSelected, boolean cellHasFocus) {
        super.getListCellRendererComponent(list, value, index, isSelected, cellHasFocus);

        if (value instanceof IRenderIcon && value != null) {
            setIcon(((IRenderIcon) value).getIcon());
        }

        if (value instanceof IRenderText && value != null) {
            String text = ((IRenderText) value).getText();
            setText(text == null ? "" : text);
        }

        return this;
    }

}
